home *** CD-ROM | disk | FTP | other *** search
/ Developer Helper 1: Phil & Dave's Excellent CD / Excellent CD HFS.raw / Moof / Goodies / HyperCard Goodies / HyperCard Dev. ToolKit / XCMD.Sources / bufferSPort.p < prev    next >
Text File  |  1987-08-17  |  2KB  |  94 lines

  1. {$R-}
  2.  
  3. (*
  4.     bufferSPort(port number, oldBuffer,sizeOfBuffer) -- Free the old buffer at the address specified by
  5.     oldBuffer (if non-zero), and allocate a new buffer of sizeOfBuffer (or revert to default buffer if
  6.     zero). Return the address of the allocated buffer or zero if sizeOfBuffer is zero.
  7.  
  8.     By Harry Chesley.  DO NOT call the author!  Contact Apple Developer 
  9.     Support on AppleLink "MacDTS" or on MCI "MacTech".
  10.  
  11.     ©Apple Computer, Inc. 1987
  12.     All Rights Reserved.
  13.  
  14.     To compile and link this file using Macintosh Programmer's Workshop,
  15.  
  16.     pascal -w bufferSPort.p
  17.     link -m ENTRYPOINT -o HyperTerm -rt XFCN=3 -sn Main=bufferSPort bufferSPort.p.o "{MPW}"Libraries:interface.o
  18.     
  19. *)
  20.  
  21. {$S bufferSPort }     { Segment name must be the same as the command name. }
  22.  
  23. unit DummyUnit;
  24.  
  25. interface
  26.  
  27. uses MemTypes, QuickDraw, OSIntf, ToolIntf, HyperXCmd;
  28.  
  29. procedure EntryPoint(paramPtr: XCmdPtr);
  30.     
  31. implementation
  32.  
  33. const
  34.  
  35. return = chr(13);
  36. linefeed = chr(10);
  37. bs = chr(8);
  38.  
  39. type
  40.  
  41. Str31 = String[31];
  42.  
  43. procedure bufferSPort(paramPtr: XCmdPtr); forward;
  44.  
  45. procedure EntryPoint(paramPtr: XCmdPtr);
  46.  
  47.     begin
  48.         bufferSPort(paramPtr);
  49.     end;
  50.  
  51. procedure bufferSPort(paramPtr: XCmdPtr);
  52.  
  53.     var portNumber: integer;
  54.         oldBufferPtr: Ptr;
  55.         newBufferPtr: Ptr;
  56.         newBufferSize: longInt;
  57.         inPort, outPort: integer;
  58.         str: Str255;
  59.  
  60.     {$I XCmdGlue.inc}
  61.  
  62.     procedure Fail(errMsg: Str255); { set theResult and quit }
  63.         begin
  64.             paramPtr^.returnValue := PasToZero(errMsg);
  65.             exit(bufferSPort);
  66.         end;
  67.  
  68.     begin
  69.         if paramPtr^.paramCount <> 3 then Fail('parameter count is not 3');
  70.  
  71.         ZeroToPas(paramPtr^.params[1]^,str);        { First parameter is port number. }
  72.         portNumber := StrToNum(str);
  73.         if (portNumber < 1) or (portNumber > 2) then Fail('invalid port number');
  74.         ZeroToPas(paramPtr^.params[2]^,str);        { Second parameter is old buffer address. }
  75.         oldBufferPtr := Ptr(StrToNum(str));
  76.         ZeroToPas(paramPtr^.params[3]^,str);        { Third parameter is new buffer size. }
  77.         newBufferSize := StrToNum(str);
  78.  
  79.         if portNumber = 1 then inPort := -6
  80.         else inPort := -8;
  81.  
  82.         if newBufferSize = 0 then newBufferPtr := nil
  83.         else newBufferPtr := NewPtr(newBufferSize);
  84.         if SerSetBuf(inPort,newBufferPtr,newBufferSize) <> noErr then
  85.             begin
  86.                 DisposPtr(newBufferPtr);
  87.                 Fail('SetSetBuf failed');
  88.             end;
  89.         if oldBufferPtr <> NIL then DisposPtr(oldBufferPtr);
  90.         str := LongToStr(ord4(newBufferPtr));
  91.         paramPtr^.returnValue := PasToZero(str);
  92.     end;
  93. end.
  94.